package com.github.soiff.shadow.autoconfigure;

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.io.TemplateLoader;
import com.github.soiff.shadow.loader.HandlebarsLoader;
import com.github.soiff.shadow.plugins.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.soiff.shadow.endpoints.PluginEndpoint;

/**
 * Created by Soiff on 2016/05/19.
 *
 * @author : Soiff
 */
@Configuration
public class SoiffShadowAutoConfigure {

    @Bean
    @ConditionalOnEnabledEndpoint(PluginEndpoint.endpoint)
    public PluginEndpoint getPlugin() {
        return new PluginEndpoint();
    }

    @Bean
    @ConditionalOnMissingBean
    public TemplateLoader getTemplateLoader () {
        return new HandlebarsLoader(Context.finders);
    }

    @Autowired
    @Bean
    @ConditionalOnMissingBean
    public Handlebars getHandlebars (TemplateLoader loader) {
        return new Handlebars(loader);
    }

    @Bean
    public WebMvcConfigurator getWebMvcConfigurator() {
        return new WebMvcConfigurator();
    }
}
